import express from 'express'
import cors from 'cors'
import morgan from 'morgan'

import { datasource } from './db/index.js'
// 初始化数据库
await datasource.initialize()
console.log('数据库连接成功')

const app = express()

import authMiddleware from './middleware/auth.js'
import errorMiddleware from './middleware/errorHandler.js'

import router from './router/index.js'

app.use(morgan('tiny'))

app.use(cors())

app.use(express.json())

app.use(authMiddleware)

router(app)

app.use(errorMiddleware)

app.listen(3001, () => {
  console.log('监听 http://localhost:3001')
})
